<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="line-big" id="write_goods_info_div">
	<div class="xl1"></div>
	<div class="xl10">
		<div class="panel border-back">
			<div class="panel-body text-center">
				<h1>
					<strong>添加微信推送客服人员</strong>
				</h1>
			</div>
			<div class="panel-foot bg-white border-back">
				<div class="line-big G-MarginTopBottom20">
					<div class="xl4">
						<div class="form-group">
							<div class="label">
								<label for="buyerId">*买家编号(25位)</label>
							</div>
							<div class="field">
								<input type="text" class="input" value="" id="buyerId" data-regex="^\S.{0,23}\S$" />
							</div>
						</div>
					</div>
					<div class="xl3">
						<div class="label">
							<label for="kefuNickname">*客服昵称(2-20个字)</label>
						</div>
						<div class="field">
							<input type="text" class="input" id="kefuNickname" value="" data-regex="^\S.{0,18}\S$" />
						</div>
					</div>
				</div>
				
				
				
			</div>
			<div class="panel-foot bg-white">
				<div class="line-big G-MarginTopBottom20">
					<div class="xl4"></div>
					<div class="xl4 text-center">
						<button class="button border-blue" id="submit_kefu_button">提交微信推送客服名单</button>
					</div>
					<div class="xl4"></div>
				</div>
			</div>
		</div>

	</div>
	<div class="xl1"></div>
</div>

<div id="add_success_div" class="G-MarginTop100" style="display: none;">
	<div class="line-big">
		<div class="xl3"></div>
		<div class="xl6 text-center">
			<h1 class="text-center">
				<span class="icon-check-circle text-yellow"></span> 提交微信推送客服名单成功了。
			</h1>
			<br />
			<p>
				<button class="button border-main click_go_to_nav_button" data-trigger-id="#sub_see_kefu_list">查看所有微信推送客服</button>
			</p>
		</div>
		<div class="xl3"></div>
	</div>
</div>

<div class="clearfix G-MarginTop100"></div>
<div style="display: none" id="time_temp_div"></div>
<script type="text/javascript">
	$(function()
	{
		var myDate = new Date();
		$("#time_temp_div").html(myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() + "-" + myDate.getMilliseconds());

		$("#submit_kefu_button").click(function()
		{
			var buyerId = $("#buyerId").val();
			var kefuNickname = $("#kefuNickname").val();

			if (buyerId.length <= 0 || kefuNickname.length <= 0)
			{
				alert("标有*的输入项都是必填项.")
				return false;
			}

			var tips = "";
			var tips_number = 1;
			$("input[data-regex]").each(function(i, dom)
			{
				var n = $(dom);
				if (new RegExp(n.attr("data-regex")).test(n.val()) == false)
				{
					tips += tips_number++ + " . \"" + n.val() + "\" 不满足输入要求;\n";
				}
			});
			if (tips.length > 0)
			{
				alert(tips + "\n请检查一下重新输入.");
				return false;
			}

			var submit_kefu_button_html = $("#submit_kefu_button").html();
			$.ajax(
			{
				url : "admin/m_add_kefu_do",
				type : "POST",
				dataType : "json",
				beforeSend : function(XMLHttpRequest)
				{
					$("#submit_kefu_button").attr("disabled", "disabled");
					$("#submit_kefu_button").html("正在提交客服信息中...");
				},
				data :
				{
					'kefu.buyerId' : buyerId,
					'kefu.kefuNickname' : kefuNickname
				},
				success : function(json, textStatus)
				{
					if (json.success == true)
					{
						$("#write_goods_info_div").slideUp();
						$("#add_success_div").slideDown(function()
						{
							$(".admin").animate(
							{
								scrollTop : 0
							}, 0);
						});

					}
					else
					{
						alert(json.info);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown)
				{
					alert("提交失败，请仔细检查您的输入是否满足要求。");
				},
				complete : function(XMLHttpRequest, textStatus)
				{
					$("#submit_kefu_button").removeAttr("disabled");
					$("#submit_kefu_button").html(submit_kefu_button_html);
				}
			});
		});

	});
</script>